<template>
  <div>
    <div class="header">
      <div class="h-left">
        <img @click="bac()" :src="'./static/lyl/back.png'" alt="">
        <span>收藏</span>
      </div>
      <div class="h-right">
        <img @click="dele()" src="../../../assets/img/delete2.png" alt="">
      </div>
    </div>
    <ul class="h_ul">
      <li v-for="(item,index) in hisData" :key="index">
        <div class="h_left">
          <img :src="item.thumb" alt="加载失败">
        </div>
        <div class="h_right">
          <p>{{item.video_title}}</p>
          <!--<p>来自 {{item.author}}</p>-->
        </div>
      </li>
    </ul>
  </div>
</template>

<script>
  import {Dialog} from 'vant';
  import * as search from "../../../api/search.js"
  export default {
    name: "Shoucang",
    data(){
      return {
        hisData:[]
      }
    },
    beforeMount(){

      //我的收藏记录
      let parms = {user_id:this.$store.state.user_id}
      search.userFavorites(parms).then(res=>{
        console.log('我的收藏',res);
        this.hisData = res.data;
        var ids;
        for (let i = 0,len = res.data.length; i < len; i++) {
          ids = res.data[i].id + ','
        }
        this.$store.commit('setids',ids);
      })
    },
    methods:{
      bac(){
        history.go(-1)
      },
      dele(){
        //删除收藏
        console.log(this.$store.state.ids)
        let parms = {user_id:this.$store.state.user_id,ids:this.$store.state.ids}
        search.deleteFavorites(parms).then(res=>{
          console.log('删除收藏',res)
          if (res.code==0){
            Dialog.alert({
              message: res.msg
            });
            history.go(-1);
          }
        })
      }
    }
  }
</script>

<style scoped>
  .header{
    border-bottom: 2px solid #dcdcdc;
    padding: 20px 40px;
    display: flex;
    justify-content: space-between;
  }
  .header .h-left img{
    width: 22px;
    vertical-align: bottom;
    margin-right: 30px;
  }
  .header .h-left span{
    font-size: 36px;
  }
  .header .h-right img{
    width: 40px;
    height: 40px;
    align-self: center;
  }
  .h_ul{
    padding: 20px 40px;
  }
  .h_ul li{
    display: flex;
    padding-bottom: 25px;
  }
  .h_ul li:last-child{
    padding-bottom: 0;
  }
  .h_ul li .h_left{
    margin-right: 30px;
  }
  .h_ul li .h_left img{
    width: 350px;
    height: 190px;
  }
  .h_ul li .h_right{
    align-self: center;
  }
  .h_ul li .h_right p:nth-child(1){
    font-size: 24px;
    line-height: 54px;
  }
  .h_ul li .h_right p:nth-child(2){
    font-size: 18px;
    line-height: 54px;
    color: #868686;
  }
</style>
